function [VecGroupCoAuthors,nArticlePublished,nCoAuthors,ValueResultsPhD,VecResultsTotal,VecResultsOriginal,VecResultsReview,VecCoAuthorsBefore,VecCoAuthorsEditor,VecJournalEditorAfter,VecResultsArticleTemp3]=FilterAuthors2(ValueFolder,n2,ValueYearEditor,LowerBoundMonth,VecEditors1Temp,VecSpecialCharacters)

VecValueDateArticle=[];
VecValueDateArticle2=[];
ValueFolder2='/sps/isc/rneveu/EtudeIRM/Nature/ResultsEditor/';
nArticle=0;
VecResultsArticle={};
VecResultsAffiliation={};
VecResultsKeyWords={};
VecAffiliationAuthors=ExtractAffiliation(VecEditors1Temp{n2,7},VecSpecialCharacters);
VecResultsTotal=[];
VecResultsOriginal=[];
VecResultsReview=[];
VecJournal=[];
VecCoAuthorsBefore=[]; % Contains the number of co authors for a given editor in each article published before he became editor
VecJournalEditorAfter=[]; % Contains, in column 1 the article number in the block which has been published after the arival of the editor at Nature and in column 2, the block number
VecCoAuthorsEditor={}; % contains the position of the co author among all the papers published with the editor. Each column represents an independant author and each line a group of authors given by VecGroupCoAuthors
VecArticleType={'Academic Dissertation' 'Adaptive Clinical Trial' 'Clinical Trial' 'Comparative Study' 'Controlled Clinical Trial' 'Equivalence Trial' 'Evaluation Study' 'Journal Article' 'Meta-Analysis' 'Multicenter Study' 'Observational Study' 'Pragmatic Clinical Trial' 'Randomized Controlled Trial' 'Review' 'Statistics' 'Technical Report' 'Systematic Review' 'Twin Study' 'Validation Study'};
VecArticleType2={'Review' 'Systematic Review'};
n1Temp2=0;
% try
    ValueFile=['ResultsCharacteristicsTempEditor' num2str(n2) '.mat'];
    ValueTemp=dir([ValueFolder2 ValueFile]);
    if size(ValueTemp,1)>0
        load([ValueFolder2 ValueFile]);
        n1Temp2=n1;
    end
% end
n1Temp2=n1Temp2+1;
n1Temp2
for n1=n1Temp2:1062
    eval(sprintf('load([ValueFolder ''Results/ResultsFile%d.mat'']);',n1));
    eval(sprintf('VecValueTemp=VecResultEditors%d;',n2));
    n1
    for n3=1:size(VecValueTemp,1)
        ValueTemp=VecValueTemp{n3,1};
        if size(ValueTemp,2)>1
            [ValueFirst,ValueLast,ValueAffiliation,ValueORCID,nAuthors]=ExtractAuthor(ValueTemp,0,1);
%             if nAuthors>1
                VecResultsArticleTemp={};
                VecResultsArticleTemp(1,1)={1};
                VecResultsArticleTemp(1,2)={nAuthors-1};
                TestArticle=0;
                ValueAffiliationEditor='';
                ValueAffiliationTemp='';
                nAffiliation=0;
                VecResultsTotalTemp=zeros(1,6);
                VecResultsOriginalTemp=zeros(1,6);
                VecResultsReviewTemp=zeros(1,6);
                VecCoAuthorsEditorTemp=zeros(1,nAuthors-1);
                n42=1;
                for n41=1:nAuthors
                    [ValueFirst,ValueLast,ValueAffiliation,ValueORCID,nAuthorsTemp]=ExtractAuthor(ValueTemp,n41,2);
                    if size(ValueAffiliation,2)>1&&size(ValueAffiliationTemp,2)==0
                        ValueAffiliationTemp=ValueAffiliation;
                    else
                        if size(ValueAffiliation,2)>1&&size(ValueAffiliationTemp,2)>1
                            ValueResult=CompareAffiliation(ValueAffiliation,ValueAffiliationTemp);
                            if ValueResult==0
                                nAffiliation=nAffiliation+1;
                            end
                        end
                    end
                    if strcmps(double([VecEditors1Temp{n2,2} ' ' VecEditors1Temp{n2,1}]),double([ValueLast ' ' ValueFirst]),VecSpecialCharacters)<0.5||TestArticle>=1
                        if TestArticle==2
                            % We have already found the editor among authors with the editors affiliation corresponding to the one collected in the editor's biography
                            VecResultsArticleTemp(1,n42+2)={[ValueLast ' ' ValueFirst]};
                            VecCoAuthorsEditorTemp(1,n42)=n41;
                            n42=n42+1;
                        else
                            ValueResults=checkEditorAffiliation(ValueAffiliation,VecAffiliationAuthors);
                            if ValueResults==1&&strcmps(double([VecEditors1Temp{n2,2} ' ' VecEditors1Temp{n2,1}]),double([ValueLast ' ' ValueFirst]),VecSpecialCharacters)>0.99
                                % We have found again the editor
                                ValueAffiliationEditor=ValueAffiliation;
                                TestArticle=2;
                                VecCoAuthorsEditorTemp(1,n42)=NaN;
                                ValueArticleType=ComputeArticleType(VecValueTemp{n3,9},VecArticleType,VecValueTemp{n3,13},VecValueTemp{n3,14});
                                if ValueArticleType>0&&nAuthors>1
                                    VecResultsOriginalTemp(1,1)=1;
                                    VecResultsTotalTemp(1,1)=1;
                                    VecResultsOriginalTemp(1,6)=n41;
                                    VecResultsTotalTemp(1,6)=n41;
                                    if n41==1
                                        VecResultsOriginalTemp(1,2)=1;
                                        VecResultsTotalTemp(1,2)=1;
                                    else
                                        if n41<nAuthors
                                            if n41==2
                                                VecResultsOriginalTemp(1,3)=1;
                                                VecResultsTotalTemp(1,3)=1;
                                            else
                                                VecResultsOriginalTemp(1,4)=1;
                                                VecResultsTotalTemp(1,4)=1;
                                            end
                                        else
                                            VecResultsOriginalTemp(1,5)=1;
                                            VecResultsTotalTemp(1,5)=1;
                                        end
                                    end
                                else
                                    ValueArticleType=ComputeArticleType(VecValueTemp{n3,9},VecArticleType2,VecValueTemp{n3,13},VecValueTemp{n3,14});
                                    if ValueArticleType>0&&nAuthors>1
                                        VecResultsReviewTemp(1,1)=1;
                                        VecResultsTotalTemp(1,1)=1;
                                        VecResultsReviewTemp(1,6)=n41;
                                        VecResultsTotalTemp(1,6)=n41;
                                        if n41==1
                                            VecResultsReviewTemp(1,2)=1;
                                            VecResultsTotalTemp(1,2)=1;
                                        else
                                            if n41<nAuthors
                                                if n41==2
                                                    VecResultsReviewTemp(1,3)=1;
                                                    VecResultsTotalTemp(1,3)=1;
                                                else
                                                    VecResultsReviewTemp(1,4)=1;
                                                    VecResultsTotalTemp(1,4)=1;
                                                end
                                            else
                                                VecResultsReviewTemp(1,5)=1;
                                                VecResultsTotalTemp(1,5)=1;
                                            end
                                        end
                                    else
                                        VecResultsTotalTemp(1,1)=1;
                                        VecResultsTotalTemp(1,6)=n41;
                                        if n41==1
                                            VecResultsTotalTemp(1,2)=1;
                                        else
                                            if n41<nAuthors
                                                if n41==2
                                                    VecResultsTotalTemp(1,3)=1;
                                                else
                                                    VecResultsTotalTemp(1,4)=1;
                                                end
                                            else
                                                VecResultsTotalTemp(1,5)=1;
                                            end
                                        end
                                    end
                                end
                                VecResultsTotal(end,:)=VecResultsTotalTemp;
                                VecResultsOriginal(end,:)=VecResultsOriginalTemp;
                                VecResultsReview(end,:)=VecResultsReviewTemp;
                            else
                                % Other cases
                                VecCoAuthorsEditorTemp(1,n42)=n41;
                            end
                            VecResultsArticleTemp(1,n42+2)={[ValueLast ' ' ValueFirst]};
                            n42=n42+1;
                        end
                    else
                        % We have found the editor among authors for the first time
                        if TestArticle==0
                            TestArticle=1;
                            ValueAffiliationEditor=ValueAffiliation;
                            ValueResults=checkEditorAffiliation(ValueAffiliation,VecAffiliationAuthors);
                            if ValueResults==1
                                TestArticle=2;
                            end
                            VecCoAuthorsBefore=[VecCoAuthorsBefore;nAuthors-1];
                            VecJournal=[VecJournal;VecValueTemp(n3,4)];
                            ValueArticleType=ComputeArticleType(VecValueTemp{n3,9},VecArticleType,VecValueTemp{n3,13},VecValueTemp{n3,14});
                            if ValueArticleType>0&&nAuthors>1
                                VecResultsOriginalTemp(1,1)=1;
                                VecResultsTotalTemp(1,1)=1;
                                VecResultsOriginalTemp(1,6)=n41;
                                VecResultsTotalTemp(1,6)=n41;
                                if n41==1
                                    VecResultsOriginalTemp(1,2)=1;
                                    VecResultsTotalTemp(1,2)=1;
                                else
                                    if n41<nAuthors
                                        if n41==2
                                            VecResultsOriginalTemp(1,3)=1;
                                            VecResultsTotalTemp(1,3)=1;
                                        else
                                            VecResultsOriginalTemp(1,4)=1;
                                            VecResultsTotalTemp(1,4)=1;
                                        end
                                    else
                                        VecResultsOriginalTemp(1,5)=1;
                                        VecResultsTotalTemp(1,5)=1;
                                    end
                                end
                            else
                                ValueArticleType=ComputeArticleType(VecValueTemp{n3,9},VecArticleType2,VecValueTemp{n3,13},VecValueTemp{n3,14});
                                if ValueArticleType>0&&nAuthors>1
                                    VecResultsReviewTemp(1,1)=1;
                                    VecResultsTotalTemp(1,1)=1;
                                    VecResultsReviewTemp(1,6)=n41;
                                    VecResultsTotalTemp(1,6)=n41;
                                    if n41==1
                                        VecResultsReviewTemp(1,2)=1;
                                        VecResultsTotalTemp(1,2)=1;
                                    else
                                        if n41<nAuthors
                                            if n41==2
                                                VecResultsReviewTemp(1,3)=1;
                                                VecResultsTotalTemp(1,3)=1;
                                            else
                                                VecResultsReviewTemp(1,4)=1;
                                                VecResultsTotalTemp(1,4)=1;
                                            end
                                        else
                                            VecResultsReviewTemp(1,5)=1;
                                            VecResultsTotalTemp(1,5)=1;
                                        end
                                    end
                                else
                                    VecResultsTotalTemp(1,1)=1;
                                    VecResultsTotalTemp(1,6)=n41;
                                    if n41==1
                                        VecResultsTotalTemp(1,2)=1;
                                    else
                                        if n41<nAuthors
                                            if n41==2
                                                VecResultsTotalTemp(1,3)=1;
                                            else
                                                VecResultsTotalTemp(1,4)=1;
                                            end
                                        else
                                            VecResultsTotalTemp(1,5)=1;
                                        end
                                    end
                                end
                            end
                            VecResultsTotal=[VecResultsTotal;VecResultsTotalTemp];
                            VecResultsOriginal=[VecResultsOriginal;VecResultsOriginalTemp];
                            VecResultsReview=[VecResultsReview;VecResultsReviewTemp];
                        end
                    end
                end
                if TestArticle>=1
                    nArticle=nArticle+1;
                    VecKeyWordsTemp=ExtractKeyWords(VecValueTemp{n3,7});
                    for n41=1:size(VecKeyWordsTemp,2)
                        VecResultsKeyWords(nArticle,n41+1)=VecKeyWordsTemp(1,n41);
                    end
                    VecResultsKeyWords(nArticle,1)={size(VecKeyWordsTemp,2)};
                    VecResultsArticle(nArticle,1)={nArticle};
                    VecResultsArticle(nArticle,2)={nAuthors-1};
                    if size(ValueAffiliationEditor,2)>1
                        VecResultsAffiliation(nArticle,1)={ValueAffiliationEditor};
                    else
                        if nAffiliation==1
                            VecResultsAffiliation(nArticle,1)={ValueAffiliationTemp};
                        else
                            VecResultsAffiliation(nArticle,1)={''};
                        end
                    end
                    for n5=1:size(VecResultsArticleTemp,2)-2
                        VecResultsArticle(nArticle,n5+2)=VecResultsArticleTemp(1,n5+2);
                    end
                    VecCoAuthorsEditor(nArticle,1)={VecCoAuthorsEditorTemp};
                    ValueDate=VecValueTemp{n3,5};
                    [ValueYear,ValueMonth,ValueDay]=ExtractDate(ValueDate);
                    ValueDateArticleTemp=[{ValueYear} {ValueMonth} {ValueDay}];
                    if size(ValueDay,2)==0
                        ValueDay='01';
                    end
                    if size(ValueMonth,2)==0
                        ValueMonth='Jan';
                    end
                    if size(ValueYear,2)>0
                        VecValueDateArticle=[VecValueDateArticle;datenum([ValueDay '-' ValueMonth '-' ValueYear],'dd-mmm-yyyy')];
                        VecValueDateArticle2=[VecValueDateArticle2;ValueDateArticleTemp];
                    else
                        VecValueDateArticle=[VecValueDateArticle;NaN];
                        ValueDateArticleTemp=[{ValueYear} {ValueMonth} {ValueDay}];
                    end
                end
%             end
        end
    end
%     if mod(n1,100)==0
%         ValueFile=['ResultsCharacteristicsTempEditor' num2str(n2) '.mat'];
%         save([ValueFolder2 ValueFile]);
%     end
    if mod(n1,5)==0
        ValueFile=['ResultsCharacteristicsTempEditor' num2str(n2) '.mat'];
        save([ValueFolder2 ValueFile],'-v7.3');
    end
end

% Keep only articles which publication date is before the editor arrival at Nature and which is not separated from the previous article published by the editor by more than 5 years
% for n1=1:size(VecResultsArticle,1)
%     ValueTemp=VecResultsArticle{n1,2};
%     if ValueTemp~=VecCoAuthorsBefore(n1,1)
%         n1
%     end
% end
[ValueTempDate,ValueTempDate2]=sort(VecValueDateArticle);
ValueTempDate3=find(isnan(ValueTempDate)==0);
ValueTempDate=ValueTempDate(ValueTempDate3,:);
ValueTempDate2=ValueTempDate2(ValueTempDate3,:);
VecResultsArticle=VecResultsArticle(ValueTempDate2,:);
VecResultsAffiliation=VecResultsAffiliation(ValueTempDate2,:);
VecResultsKeyWords=VecResultsKeyWords(ValueTempDate2,:);
VecResultsTotal=VecResultsTotal(ValueTempDate2,:);
VecResultsOriginal=VecResultsOriginal(ValueTempDate2,:);
VecResultsReview=VecResultsReview(ValueTempDate2,:);
VecCoAuthorsBefore=VecCoAuthorsBefore(ValueTempDate2,:);
VecCoAuthorsEditor=VecCoAuthorsEditor(ValueTempDate2,:);
VecJournal=VecJournal(ValueTempDate2,:);
LowerBoundMonthTemp=num2str(LowerBoundMonth);
ValueYearEditorTemp=num2str(ValueYearEditor);
if LowerBoundMonth<10
    ValueDateEditor=datenum(['01-0' LowerBoundMonthTemp '-' ValueYearEditorTemp],'dd-mmm-yyyy');
else
    ValueDateEditor=datenum(['01-' LowerBoundMonthTemp '-' ValueYearEditorTemp],'dd-mmm-yyyy');
end
ValueTempDate3=find(ValueTempDate<ValueDateEditor);
nMax=size(ValueTempDate3,1);
VecCoAuthorsBeforeTemp=VecCoAuthorsBefore(nMax+1:end,:);
if size(VecCoAuthorsBeforeTemp,1)>0
    VecResultsArticleTemp=VecResultsArticle(nMax+1:end,:);
    VecJournalTemp=VecJournal(nMax+1:end,:);
    ValueCoAuthors=find(VecCoAuthorsBeforeTemp(:,1)>1);
    if size(ValueCoAuthors,1)>=1
        VecCoAuthorsBeforeTemp=VecCoAuthorsBeforeTemp(ValueCoAuthors,:);
        VecResultsArticleTemp=VecResultsArticleTemp(ValueCoAuthors,:);
        VecJournalTemp=VecJournalTemp(ValueCoAuthors,:);
        for n1=1:size(VecResultsArticleTemp,1)
            VecJournalEditorAfter=[VecJournalEditorAfter;{VecCoAuthorsBeforeTemp(n1,1)} {VecResultsArticleTemp} {VecJournalTemp(n1,1)}];
        end
    end
end
if size(VecEditors1Temp{n2,20},2)>=1&&ischar(VecEditors1Temp{n2,20})==0
    ValueDateEditor2=datenum(['31-12-' num2str(VecEditors1Temp{n2,20})],'dd-mmm-yyyy');
    if ValueDateEditor2<ValueDateEditor
        ValueDateEditor=ValueDateEditor2;
    end
end
if size(VecEditors1Temp{n2,18},2)>=1&&ischar(VecEditors1Temp{n2,18})==0
    ValueDateEditor3=datenum(['01-01-' num2str(VecEditors1Temp{n2,18})],'dd-mmm-yyyy');
end
if size(VecEditors1Temp{n2,19},2)>=1&&ischar(VecEditors1Temp{n2,19})==0
    ValueDateEditor4=datenum(['31-12-' num2str(VecEditors1Temp{n2,19})],'dd-mmm-yyyy');
end
% ValueTempDate3=ValueTempDate(2:end,1)-ValueTempDate(1:end-1,1);
ValueTempDate3=find(ValueTempDate<ValueDateEditor);
ValueTempDate4=find(ValueTempDate>ValueDateEditor3);
ValueTempDate5=find(ValueTempDate>ValueDateEditor3&ValueTempDate<ValueDateEditor4);
ValueResultsPhD(1,1)=size(ValueTempDate5,1);
ValueResultsPhD(2,1)=VecEditors1Temp{n2,19}-VecEditors1Temp{n2,18}+1;
nMax=size(ValueTempDate3,1);
if size(ValueTempDate4,1)>=1
    nMinTemp=ValueTempDate4(1,1);
else
    nMinTemp=1;
end
VecResultsArticle=VecResultsArticle(nMinTemp:nMax,:);
VecResultsAffiliation=VecResultsAffiliation(nMinTemp:nMax,:);
VecResultsKeyWords=VecResultsKeyWords(nMinTemp:nMax,:);
ValueTempDate=ValueTempDate(nMinTemp:nMax,:);
VecResultsTotal=VecResultsTotal(nMinTemp:nMax,:);
VecResultsOriginal=VecResultsOriginal(nMinTemp:nMax,:);
VecResultsReview=VecResultsReview(nMinTemp:nMax,:);
VecCoAuthorsBefore=VecCoAuthorsBefore(nMinTemp:nMax,:);
VecCoAuthorsEditor=VecCoAuthorsEditor(nMinTemp:nMax,:);
% if size(ValueTempDate,1)>1
%     ValueTempDateTemp=ValueTempDate(2:end,1)-ValueTempDate(1:end-1,1);
%     ValueTempDateTemp2=find(ValueTempDateTemp>5*365.25);
%     if size(ValueTempDateTemp2,1)>=1
%         nMin=ValueTempDateTemp2(end,1)+1;
%     else
%         nMin=1;
%     end
% else
%     nMin=1;
% end
nMin=1;
ValueTempDate=ValueTempDate(nMin:end,:);
% datestr(ValueTempDate(1,1))
VecResultsArticle=VecResultsArticle(nMin:end,:);
VecResultsAffiliation=VecResultsAffiliation(nMin:end,:);
VecResultsKeyWords=VecResultsKeyWords(nMin:end,:);
VecCoAuthorsBefore=VecCoAuthorsBefore(nMin:end,:);
VecCoAuthorsEditor=VecCoAuthorsEditor(nMin:end,:);
VecResultsTotal=[VecResultsTotal(nMin:end,:) ValueTempDate VecCoAuthorsBefore zeros(size(ValueTempDate,1),1)];
VecResultsOriginal=[VecResultsOriginal(nMin:end,:) ValueTempDate VecCoAuthorsBefore zeros(size(ValueTempDate,1),1)];
VecResultsReview=[VecResultsReview(nMin:end,:) ValueTempDate VecCoAuthorsBefore zeros(size(ValueTempDate,1),1)];

% Make group of articles based on affiliation keywords and co authors who are in common
TestTemp5=0;
n52=size(VecResultsArticle,1);
VecResultsArticleTemp3={[]};
if n52>=1
    VecCoAuthorsEditorTemp2=[];
    VecResultsArticleTemp2={};
    nMaxArticle=size(VecResultsArticle,1);
    while n52>=1&&TestTemp5==0
        if VecCoAuthorsBefore(n52,1)>0
            nMaxArticle=n52;
        end
        ValueResultsAffiliation=VecResultsAffiliation{n52,1};
        TestTemp=0;
        if size(ValueResultsAffiliation,2)>1&&size(VecAffiliationAuthors,2)>=1
            TestTemp2=0;
            n3=1;
            while n3<=size(ValueResultsAffiliation,2)-2&&TestTemp2==0
                if strcmpi(ValueResultsAffiliation(1,n3:n3+2),'Uni')==1
                    TestTemp2=n3;
                end
                n3=n3+1;
            end
            TestTemp3=0;
            TestTemp4=0;
            for n4=1:size(VecAffiliationAuthors,2)
                ValueAffiliationAuthors3=VecAffiliationAuthors{1,n4};
                ValueTemp5=size(ValueAffiliationAuthors3,2);
                n3=1;
                while n3<=size(ValueResultsAffiliation,2)-ValueTemp5+1&&TestTemp3==0
                    if strcmpi(ValueResultsAffiliation(1,n3:n3+ValueTemp5-1),ValueAffiliationAuthors3)==1
                        TestTemp3=n3;
                        if VecAffiliationAuthors{2,n4}>0
                            TestTemp4=VecAffiliationAuthors{2,n4};
                        end
                    end
                    n3=n3+1;
                end
            end
            if TestTemp3>0
                if TestTemp2>0&&TestTemp4>0
                    TestTemp=1;
                else
                    if TestTemp2==0&&TestTemp4==0
                        TestTemp=1;
                    end
                end
            end
        end
        if TestTemp==1
            VecResultsArticleTemp=VecResultsArticle(n52,2:end);
            VecResultsArticleTemp2(1,1)={VecResultsArticle(n52,1)};
            VecResultsArticleTemp3(1,1)={1};
            VecResultsKeyWordsTemp=VecResultsKeyWords(n52,:);
            VecResultsAffiliationTemp=VecResultsAffiliation(n52,1);
            VecResultsTotal(n52,end)=1;
            VecResultsOriginal(n52,end)=1;
            VecResultsReview(n52,end)=1;
            ValueCoAuthorsEditor=VecCoAuthorsEditor{n52,1};
            VecCoAuthorsEditorTemp2={size(ValueCoAuthorsEditor,2)};
            for n42=1:size(ValueCoAuthorsEditor,2)
                VecCoAuthorsEditorTemp2=[VecCoAuthorsEditorTemp2 {ValueCoAuthorsEditor(1,n42)}];
            end
            TestTemp5=1;
        end
        n52=n52-1;
    end
    if TestTemp5==0
        VecResultsArticleTemp=VecResultsArticle(nMaxArticle,2:end);
        VecResultsArticleTemp2(1,1)={VecResultsArticle(nMaxArticle,1)};
        VecResultsArticleTemp3(1,1)={6};
        VecResultsKeyWordsTemp=VecResultsKeyWords(nMaxArticle,:);
        VecResultsAffiliationTemp=VecResultsAffiliation(nMaxArticle,1);
        VecResultsTotal(nMaxArticle,end)=1;
        VecResultsOriginal(nMaxArticle,end)=1;
        VecResultsReview(nMaxArticle,end)=1;
        ValueCoAuthorsEditor=VecCoAuthorsEditor{nMaxArticle,1};
        VecCoAuthorsEditorTemp2={size(ValueCoAuthorsEditor,2)};
        for n42=1:size(ValueCoAuthorsEditor,2)
            VecCoAuthorsEditorTemp2=[VecCoAuthorsEditorTemp2 {ValueCoAuthorsEditor(1,n42)}];
        end
        n52=nMaxArticle-1;
    end
    n53=n52+1;
    for n1=1:size(VecResultsArticle,1)
        if n1~=n53
        nTemp=VecResultsArticle{n1,1};
        nTemp3=VecResultsKeyWords{n1,1};
    %     if nTemp<nMax
            nTemp2=VecResultsArticle{n1,2};
            ValueResultsAffiliation=VecResultsAffiliation{n1,1};
            TestTemp=0;
            if size(ValueResultsAffiliation,2)>1&&size(VecAffiliationAuthors,2)>=1
                TestTemp2=0;
                n3=1;
                while n3<=size(ValueResultsAffiliation,2)-2&&TestTemp2==0
                    if strcmpi(ValueResultsAffiliation(1,n3:n3+2),'Uni')==1
                        TestTemp2=n3;
                    end
                    n3=n3+1;
                end
                TestTemp3=0;
                TestTemp4=0;
                for n4=1:size(VecAffiliationAuthors,2)
                    ValueAffiliationAuthors3=VecAffiliationAuthors{1,n4};
                    ValueTemp5=size(ValueAffiliationAuthors3,2);
                    n3=1;
                    while n3<=size(ValueResultsAffiliation,2)-ValueTemp5+1&&TestTemp3==0
                        if strcmpi(ValueResultsAffiliation(1,n3:n3+ValueTemp5-1),ValueAffiliationAuthors3)==1
                            TestTemp3=n3;
                            if VecAffiliationAuthors{2,n4}>0
                                TestTemp4=VecAffiliationAuthors{2,n4};
                            end
                        end
                        n3=n3+1;
                    end
                end
                if TestTemp3>0
                    if TestTemp2>0&&TestTemp4>0
                        TestTemp=1;
                    else
                        if TestTemp2==0&&TestTemp4==0
                            TestTemp=1;
                        end
                    end
                end
            end
            if TestTemp==0
                TestTemp=CompareKeyWords(TestTemp,VecResultsKeyWords,n1,VecResultsKeyWordsTemp,1);
            end
            if TestTemp==1
                n3=VecResultsArticleTemp{1,1};
                n3=n3+1;
                n52=0;
                for n2=1:nTemp2
                    TestTemp2=0;
                    n42=2;
                    while n42<=n3&&TestTemp2==0
                        ValueTemp54=VecResultsArticleTemp{1,n42};
                        ValueTemp55=VecResultsArticle{n1,n2+2};
                        if strcmps(ValueTemp54,ValueTemp55,VecSpecialCharacters)>0.99||strcmpi(ValueTemp54,ValueTemp55)==1
                            TestTemp2=n42;
                        end
                        n42=n42+1;
                    end
                    if TestTemp2==0
                        n52=n52+1;
                        VecResultsArticleTemp(1,n3+n52)=VecResultsArticle(n1,n2+2);
                        ValueCoAuthorsEditor=VecCoAuthorsEditor{n1,1};
                        ValueCoAuthorsEditor2=VecCoAuthorsEditorTemp2{1,1};
                        VecCoAuthorsEditorTemp2(1,ValueCoAuthorsEditor2+n52+1)={ValueCoAuthorsEditor(1,n2)};
                    else
                        ValueCoAuthorsEditor=VecCoAuthorsEditor{n1,1};
                        ValueCoAuthorsEditor2=VecCoAuthorsEditorTemp2{1,TestTemp2};
                        VecCoAuthorsEditorTemp2(1,TestTemp2)={[ValueCoAuthorsEditor2 ValueCoAuthorsEditor(1,n2)]};
                    end
                end
                VecResultsArticleTemp(1,1)={n3+n52-1};
                VecResultsArticleTemp3(1,1)={[VecResultsArticleTemp3{1,1} 1]};
                VecValueTemp=VecResultsArticleTemp2{1,1};
                VecValueTemp=[VecValueTemp nTemp];
                VecResultsArticleTemp2(1,1)={VecValueTemp};
                VecResultsTotal(n1,end)=1;
                VecResultsOriginal(n1,end)=1;
                VecResultsReview(n1,end)=1;
                ValueCoAuthorsEditor2=VecCoAuthorsEditorTemp2{1,1};
                VecCoAuthorsEditorTemp2(1,1)={ValueCoAuthorsEditor2+n52};
                nTemp4=VecResultsKeyWordsTemp{1,1};
                nTemp4=nTemp4+1;
                nTemp3=nTemp3+1;
                n52=0;
                for n2=2:nTemp3
                    TestTemp2=0;
                    n42=2;
                    while n42<=nTemp4&&TestTemp2==0
                        ValueTemp54=VecResultsKeyWordsTemp{1,n42};
                        ValueTemp55=VecResultsKeyWords{n1,n2};
                        if strcmpi(ValueTemp54,ValueTemp55)==1
                            TestTemp2=1;
                        end
                        n42=n42+1;
                    end
                    if TestTemp2==0
                        n52=n52+1;
                        VecResultsKeyWordsTemp(1,nTemp3+n52)=VecResultsKeyWords(n1,n2);
                    end
                end
                VecResultsKeyWordsTemp(1,1)={nTemp3+n52-1};
            else
                % Compare affiliation
                if size(ValueResultsAffiliation,2)>1
                    TestTemp=0;
                    n3=1;
                    while TestTemp==0&&n3<=size(VecResultsAffiliationTemp,1)
                        if size(VecResultsAffiliationTemp{n3,1},2)>1
                            if CompareAffiliation(ValueResultsAffiliation,VecResultsAffiliationTemp{n3,1})==1
                                TestTemp=n3;
                            end
                        end
                        n3=n3+1;
                    end
                end
                if TestTemp>0
                    n3=VecResultsArticleTemp{TestTemp,1};
                    n3=n3+1;
                    n52=0;
                    for n2=1:nTemp2
                        TestTemp2=0;
                        n42=2;
                        while n42<=n3&&TestTemp2==0
                            ValueTemp54=VecResultsArticleTemp{TestTemp,n42};
                            ValueTemp55=VecResultsArticle{n1,n2+2};
                            if strcmps(ValueTemp54,ValueTemp55,VecSpecialCharacters)>0.99||strcmpi(ValueTemp54,ValueTemp55)==1
                                TestTemp2=n42;
                            end
                            n42=n42+1;
                        end
                        if TestTemp2==0
                            n52=n52+1;
                            VecResultsArticleTemp(TestTemp,n3+n52)=VecResultsArticle(n1,n2+2);
                            ValueCoAuthorsEditor=VecCoAuthorsEditor{n1,1};
                            ValueCoAuthorsEditor2=VecCoAuthorsEditorTemp2{TestTemp,1};
                            VecCoAuthorsEditorTemp2(TestTemp,ValueCoAuthorsEditor2+n52+1)={ValueCoAuthorsEditor(1,n2)};
                        else
                            ValueCoAuthorsEditor=VecCoAuthorsEditor{n1,1};
                            ValueCoAuthorsEditor2=VecCoAuthorsEditorTemp2{TestTemp,TestTemp2};
                            VecCoAuthorsEditorTemp2(TestTemp,TestTemp2)={[ValueCoAuthorsEditor2 ValueCoAuthorsEditor(1,n2)]};
                        end
                    end
                    VecResultsArticleTemp(TestTemp,1)={n3+n52-1};
                    VecResultsArticleTemp3(TestTemp,1)={[VecResultsArticleTemp3{TestTemp,1} 2]};
                    VecValueTemp=VecResultsArticleTemp2{TestTemp,1};
                    VecValueTemp=[VecValueTemp nTemp];
                    VecResultsArticleTemp2(TestTemp,1)={VecValueTemp};
                    VecResultsTotal(n1,end)=TestTemp;
                    VecResultsOriginal(n1,end)=TestTemp;
                    VecResultsReview(n1,end)=TestTemp;
                    ValueCoAuthorsEditor2=VecCoAuthorsEditorTemp2{TestTemp,1};
                    VecCoAuthorsEditorTemp2(TestTemp,1)={ValueCoAuthorsEditor2+n52};
                    nTemp4=VecResultsKeyWordsTemp{1,1};
                    nTemp4=nTemp4+1;
                    nTemp3=nTemp3+1;
                    n52=0;
                    for n2=2:nTemp3
                        TestTemp2=0;
                        n42=2;
                        while n42<=nTemp4&&TestTemp2==0
                            ValueTemp54=VecResultsKeyWordsTemp{1,n42};
                            ValueTemp55=VecResultsKeyWords{n1,n2};
                            if strcmpi(ValueTemp54,ValueTemp55)==1
                                TestTemp2=1;
                            end
                            n42=n42+1;
                        end
                        if TestTemp2==0
                            n52=n52+1;
                            VecResultsKeyWordsTemp(1,nTemp3+n52)=VecResultsKeyWords(n1,n2);
                        end
                    end
                    VecResultsKeyWordsTemp(1,1)={nTemp3+n52-1};
                else
                    TestTemp=0;
                    n3=1;
                    while TestTemp==0&&n3<=size(VecResultsKeyWordsTemp,1)
                        TestTemp=CompareKeyWords(TestTemp,VecResultsKeyWords,n1,VecResultsKeyWordsTemp,n3);
                        n3=n3+1;
                    end
                    if TestTemp>0
                        n3=VecResultsArticleTemp{TestTemp,1};
                        n3=n3+1;
                        n52=0;
                        for n2=1:nTemp2
                            TestTemp2=0;
                            n42=2;
                            while n42<=n3&&TestTemp2==0
                                ValueTemp54=VecResultsArticleTemp{TestTemp,n42};
                                ValueTemp55=VecResultsArticle{n1,n2+2};
                                if strcmps(ValueTemp54,ValueTemp55,VecSpecialCharacters)>0.99||strcmpi(ValueTemp54,ValueTemp55)==1
                                    TestTemp2=n42;
                                end
                                n42=n42+1;
                            end
                            if TestTemp2==0
                                n52=n52+1;
                                VecResultsArticleTemp(TestTemp,n3+n52)=VecResultsArticle(n1,n2+2);
                                ValueCoAuthorsEditor=VecCoAuthorsEditor{n1,1};
                                ValueCoAuthorsEditor2=VecCoAuthorsEditorTemp2{TestTemp,1};
                                VecCoAuthorsEditorTemp2(TestTemp,ValueCoAuthorsEditor2+n52+1)={ValueCoAuthorsEditor(1,n2)};
                            else
                                ValueCoAuthorsEditor=VecCoAuthorsEditor{n1,1};
                                ValueCoAuthorsEditor2=VecCoAuthorsEditorTemp2{TestTemp,TestTemp2};
                                VecCoAuthorsEditorTemp2(TestTemp,TestTemp2)={[ValueCoAuthorsEditor2 ValueCoAuthorsEditor(1,n2)]};
                            end
                        end
                        VecResultsArticleTemp(TestTemp,1)={n3+n52-1};
                        VecResultsArticleTemp3(TestTemp,1)={[VecResultsArticleTemp3{TestTemp,1} 3]};
                        VecValueTemp=VecResultsArticleTemp2{TestTemp,1};
                        VecValueTemp=[VecValueTemp nTemp];
                        VecResultsArticleTemp2(TestTemp,1)={VecValueTemp};
                        VecResultsTotal(n1,end)=TestTemp;
                        VecResultsOriginal(n1,end)=TestTemp;
                        VecResultsReview(n1,end)=TestTemp;
                        ValueCoAuthorsEditor2=VecCoAuthorsEditorTemp2{TestTemp,1};
                        VecCoAuthorsEditorTemp2(TestTemp,1)={ValueCoAuthorsEditor2+n52};
                        nTemp4=VecResultsKeyWordsTemp{TestTemp,1};
                        nTemp4=nTemp4+1;
                        nTemp3=nTemp3+1;
                        n52=0;
                        for n2=2:nTemp3
                            TestTemp2=0;
                            n42=2;
                            while n42<=nTemp4&&TestTemp2==0
                                ValueTemp54=VecResultsKeyWordsTemp{TestTemp,n42};
                                ValueTemp55=VecResultsKeyWords{n1,n2};
                                if strcmpi(ValueTemp54,ValueTemp55)==1
                                    TestTemp2=1;
                                end
                                n42=n42+1;
                            end
                            if TestTemp2==0
                                n52=n52+1;
                                VecResultsKeyWordsTemp(TestTemp,nTemp3+n52)=VecResultsKeyWords(n1,n2);
                            end
                        end
                        VecResultsKeyWordsTemp(TestTemp,1)={nTemp3+n52-1};
                    else
                        n2=1;
                        while TestTemp==0&&n2<=nTemp2
                            n3=1;
                            while TestTemp==0&&n3<=size(VecResultsArticleTemp,1)
                                n4=2;
                                n42=VecResultsArticleTemp{n3,1};
                                while TestTemp==0&&n4<=n42
                                    if strcmps(VecResultsArticle{n1,n2+2},VecResultsArticleTemp{n3,n4+1},VecSpecialCharacters)>0.99
                                        TestTemp=n3;
                                    end
                                    n4=n4+1;
                                end
                                n3=n3+1;
                            end
                            n2=n2+1;
                        end
                        if TestTemp>0
                            n3=VecResultsArticleTemp{TestTemp,1};
                            n3=n3+1;
                            n52=0;
                            for n2=1:nTemp2
                                TestTemp2=0;
                                n42=2;
                                while n42<=n3&&TestTemp2==0
                                    ValueTemp54=VecResultsArticleTemp{TestTemp,n42};
                                    ValueTemp55=VecResultsArticle{n1,n2+2};
                                    if strcmps(ValueTemp54,ValueTemp55,VecSpecialCharacters)>0.99||strcmpi(ValueTemp54,ValueTemp55)==1
                                        TestTemp2=n42;
                                    end
                                    n42=n42+1;
                                end
                                if TestTemp2==0
                                    n52=n52+1;
                                    VecResultsArticleTemp(TestTemp,n3+n52)=VecResultsArticle(n1,n2+2);
                                    ValueCoAuthorsEditor=VecCoAuthorsEditor{n1,1};
                                    ValueCoAuthorsEditor2=VecCoAuthorsEditorTemp2{TestTemp,1};
                                    VecCoAuthorsEditorTemp2(TestTemp,ValueCoAuthorsEditor2+n52+1)={ValueCoAuthorsEditor(1,n2)};
                                else
                                    ValueCoAuthorsEditor=VecCoAuthorsEditor{n1,1};
                                    ValueCoAuthorsEditor2=VecCoAuthorsEditorTemp2{TestTemp,TestTemp2};
                                    VecCoAuthorsEditorTemp2(TestTemp,TestTemp2)={[ValueCoAuthorsEditor2 ValueCoAuthorsEditor(1,n2)]};
                                end
                            end
                            VecResultsArticleTemp(TestTemp,1)={n3+n52-1};
                            VecResultsArticleTemp3(TestTemp,1)={[VecResultsArticleTemp3{TestTemp,1} 4]};
                            VecValueTemp=VecResultsArticleTemp2{TestTemp,1};
                            VecValueTemp=[VecValueTemp nTemp];
                            VecResultsArticleTemp2(TestTemp,1)={VecValueTemp};
                            VecResultsTotal(n1,end)=TestTemp;
                            VecResultsOriginal(n1,end)=TestTemp;
                            VecResultsReview(n1,end)=TestTemp;
                            ValueCoAuthorsEditor2=VecCoAuthorsEditorTemp2{TestTemp,1};
                            VecCoAuthorsEditorTemp2(TestTemp,1)={ValueCoAuthorsEditor2+n52};
                            nTemp4=VecResultsKeyWordsTemp{TestTemp,1};
                            nTemp4=nTemp4+1;
                            nTemp3=nTemp3+1;
                            n52=0;
                            for n2=2:nTemp3
                                TestTemp2=0;
                                n42=2;
                                while n42<=nTemp4&&TestTemp2==0
                                    ValueTemp54=VecResultsKeyWordsTemp{TestTemp,n42};
                                    ValueTemp55=VecResultsKeyWords{n1,n2};
                                    if strcmpi(ValueTemp54,ValueTemp55)==1
                                        TestTemp2=1;
                                    end
                                    n42=n42+1;
                                end
                                if TestTemp2==0
                                    n52=n52+1;
                                    VecResultsKeyWordsTemp(TestTemp,nTemp3+n52)=VecResultsKeyWords(n1,n2);
                                end
                            end
                            VecResultsKeyWordsTemp(TestTemp,1)={nTemp3+n52-1};
                        else
                            n3=size(VecResultsArticleTemp,1);
                            for n2=1:nTemp2
                                VecResultsArticleTemp(n3+1,n2+1)=VecResultsArticle(n1,n2+2);
                            end
                            VecResultsArticleTemp(n3+1,1)={nTemp2};
                            VecResultsArticleTemp2(n3+1,1)={nTemp};
                            VecResultsArticleTemp3(n3+1,1)={5};
                            VecResultsAffiliationTemp(n3+1,1)=VecResultsAffiliation(n1,1);
                            VecResultsTotal(n1,end)=n3+1;
                            VecResultsOriginal(n1,end)=n3+1;
                            VecResultsReview(n1,end)=n3+1;
                            ValueCoAuthorsEditor=VecCoAuthorsEditor{n1,1};
                            VecCoAuthorsEditorTemp2(n3+1,1)={size(ValueCoAuthorsEditor,2)};
                            for n42=1:size(ValueCoAuthorsEditor,2)
                                VecCoAuthorsEditorTemp2(n3+1,n42+1)={ValueCoAuthorsEditor(1,n42)};
                            end
                            for n2=1:nTemp3+1
                                VecResultsKeyWordsTemp(n3+1,n2)=VecResultsKeyWords(n1,n2);
                            end
                        end
                    end
                end
            end
        end
    end
    % ValueResultsTest=[];
    % for n4=1:3
    % ValueTemp=VecResultsArticleTemp{n4,1};
    % for n1=2:ValueTemp+1
    %     TestTemp2=0;
    %     n3=2;
    %     while n3<=ValueTemp+1&&TestTemp2==0
    %         if n3~=n1
    %             ValueTemp54=VecResultsArticleTemp{n4,n1};
    %             ValueTemp55=VecResultsArticleTemp{n4,n3};
    %             ValueResultsTest=[ValueResultsTest;size(ValueTemp54,2) size(ValueTemp55,2)];
    %             if strcmps(ValueTemp54,ValueTemp55,VecSpecialCharacters)>0.99||strcmpi(ValueTemp54,ValueTemp55)==1
    %                 TestTemp2=1;
    %             end
    %         end
    %         n3=n3+1;
    %     end
    % end
    % end
    % ValueResultsTest

    % Merge groups of articles
    for n1=1:size(VecResultsArticleTemp,1)
        ValueTemp=VecResultsArticleTemp{n1,1};
        if ValueTemp>0
            for n2=1:size(VecResultsArticleTemp,1)
                if n2~=n1
                    ValueTemp2=VecResultsArticleTemp{n2,1};
                    if ValueTemp2>0
                        TestTemp2=0;
                        n3=2;
                        while n3<=ValueTemp+1&&TestTemp2==0
                            n42=2;
                            while n42<=ValueTemp2+1&&TestTemp2==0
                                ValueTemp54=VecResultsArticleTemp{n1,n3};
                                ValueTemp55=VecResultsArticleTemp{n2,n42};
                                if strcmps(ValueTemp54,ValueTemp55,VecSpecialCharacters)>0.99||strcmpi(ValueTemp54,ValueTemp55)==1
                                    TestTemp2=1;
                                end
                                n42=n42+1;
                            end
                            n3=n3+1;
                        end
                        if TestTemp2==1
                            n52=0;
                            for n42=2:ValueTemp2+1
                                TestTemp2=0;
                                n3=2;
                                while n3<=ValueTemp+1&&TestTemp2==0
                                    ValueTemp54=VecResultsArticleTemp{n1,n3};
                                    ValueTemp55=VecResultsArticleTemp{n2,n42};
                                    if strcmps(ValueTemp54,ValueTemp55,VecSpecialCharacters)>0.99||strcmpi(ValueTemp54,ValueTemp55)==1
                                        TestTemp2=1;
                                    end
                                    n3=n3+1;
                                end
                                if TestTemp2==0
                                    n52=n52+1;
                                    VecResultsArticleTemp(n1,ValueTemp+1+n52)={ValueTemp55};
                                end
                            end
                            VecResultsArticleTemp3(n1,1)={[VecResultsArticleTemp3{n1,1} VecResultsArticleTemp3{n2,1}]};
                            VecResultsArticleTemp3(n2,1)={[]};
                            VecResultsArticleTemp(n1,1)={ValueTemp+n52};
                            VecResultsArticleTemp(n2,1)={0};
                            ValueTemp56=find(VecResultsTotal(:,end)==n2);
                            if size(ValueTemp56,1)>=1
                                VecResultsTotal(ValueTemp56,end)=n1*ones(size(ValueTemp56,1),1);
                            end
                            ValueTemp56=find(VecResultsOriginal(:,end)==n2);
                            if size(ValueTemp56,1)>=1
                                VecResultsOriginal(ValueTemp56,end)=n1*ones(size(ValueTemp56,1),1);
                            end
                            ValueTemp56=find(VecResultsReview(:,end)==n2);
                            if size(ValueTemp56,1)>=1
                                VecResultsReview(ValueTemp56,end)=n1*ones(size(ValueTemp56,1),1);
                            end
                        end
                    end
                end
            end
        end
    end
    n1=size(VecResultsArticleTemp,1);
    while n1>=1
        if VecResultsArticleTemp{n1,1}==0
            VecResultsArticleTemp(n1,:)=[];
        end
        n1=n1-1;
    end            
    VecGroupCoAuthors=VecResultsArticleTemp;
    VecCoAuthorsEditor=VecCoAuthorsEditorTemp2;
    VecResultsTemp=zeros(size(VecResultsArticleTemp2,1),1);
    for n1=1:size(VecResultsArticleTemp2,1)
        VecResultsTemp(n1,1)=size(VecResultsArticleTemp2{n1,1},2);
    end
    % nArticlePublished=size(VecResultsArticleTemp2{1,1},2);
    nArticlePublished=VecResultsTemp;
    nCoAuthors=VecResultsArticleTemp(:,1);
else
    VecGroupCoAuthors=VecResultsArticle;
    nArticlePublished=0;
    nCoAuthors=0;
end
    

        
        
    
    